package com.ruoyi.business.controller;

import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.WorkOrder;
import com.ruoyi.business.service.IWorkOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工单Controller
 * 
 * @author lcz
 * @date 2025-02-21
 */
@Api(tags = "工单相关接口")
@RestController
@RequestMapping("/business/workOrder")
public class WorkOrderController extends BaseController
{
    @Autowired
    private IWorkOrderService workOrderService;

    /**
     * 查询工单列表
     */
    @ApiIgnore
    @PreAuthorize("@ss.hasPermi('business:workOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkOrder workOrder)
    {
        startPage();
        List<WorkOrder> list = workOrderService.selectWorkOrderList(workOrder);
        return getDataTable(list);
    }

    /**
     * 导出工单列表
     */
    @ApiIgnore
    @PreAuthorize("@ss.hasPermi('business:workOrder:export')")
    @Log(title = "工单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkOrder workOrder)
    {
        List<WorkOrder> list = workOrderService.selectWorkOrderList(workOrder);
        ExcelUtil<WorkOrder> util = new ExcelUtil<WorkOrder>(WorkOrder.class);
        util.exportExcel(response, list, "工单数据");
    }

    /**
     * 获取工单详细信息
     */
    @ApiIgnore
    @PreAuthorize("@ss.hasPermi('business:workOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(workOrderService.selectWorkOrderById(id));
    }

    /**
     * 新增工单
     */
    @ApiIgnore
    @PreAuthorize("@ss.hasPermi('business:workOrder:add')")
    @Log(title = "工单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkOrder workOrder)
    {
        return toAjax(workOrderService.insertWorkOrder(workOrder));
    }

    /**
     * 修改工单
     */
    @ApiIgnore
    @PreAuthorize("@ss.hasPermi('business:workOrder:edit')")
    @Log(title = "工单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkOrder workOrder)
    {
        return toAjax(workOrderService.updateWorkOrder(workOrder));
    }

    /**
     * 删除工单
     */
    @ApiIgnore
    @PreAuthorize("@ss.hasPermi('business:workOrder:remove')")
    @Log(title = "工单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workOrderService.deleteWorkOrderByIds(ids));
    }

    /** 前端接口 ***************************************************************************************************/
    /** 前端接口 ***************************************************************************************************/
    /** 前端接口 ***************************************************************************************************/

//    /**
//     * 查询工单列表
//     * 接口路径：/workOrder/front/list
//     */
//    @GetMapping("/front/list")
//    @ApiOperation("前台查询工单列表")
//    public TableDataInfo<WorkOrder> frontList(WorkOrder workOrder)
//    {
//        startPage();
//        List<WorkOrder> list = workOrderService.selectWorkOrderList(workOrder);
//        return getDataTable(list);
//    }
//
//    /**
//     * 获取工单详细信息
//     * 接口路径：/workOrder/front/info
//     */
//    @ApiOperation("前台获取工单详细信息")
//    @GetMapping(value = "/front/info")
//    public R<WorkOrder> frontInfo(@RequestParam("id") Long id)
//    {
//        return R.ok(workOrderService.selectWorkOrderById(id));
//    }
//
//    /**
//     * 新增工单
//     * 接口路径：/workOrder/front/add
//     */
//    @ApiOperation("前台新增工单")
//    @PostMapping("/front/add")
//    public AjaxResult frontAdd(@RequestBody WorkOrder workOrder)
//    {
//        return toAjax(workOrderService.insertWorkOrder(workOrder));
//    }
//
//    /**
//     * 修改工单
//     * 接口路径：/workOrder/front/edit
//     */
//    @ApiOperation("前台修改工单")
//    @PostMapping("/front/edit")
//    public AjaxResult frontEdit(@RequestBody WorkOrder workOrder)
//    {
//        return toAjax(workOrderService.updateWorkOrder(workOrder));
//    }
//
//    /**
//     * 删除工单
//     * 接口路径：/workOrder/front/delete
//     */
//    @ApiOperation("前台删除工单")
//    @GetMapping("/front/delete")
//    public AjaxResult frontRemove(@RequestParam Long[] ids)
//    {
//        return toAjax(workOrderService.deleteWorkOrderByIds(ids));
//    }
}
